<template>
  <el-card shadow="always" :body-style="{ padding: '20px' }">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="一级分类">
        <el-select placeholder="请选择一级分类" v-model="category1Id">
          <el-option
            :label="item.name"
            :value="item.id"
            v-for="item in category1List"
            :key="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select placeholder="请选择二级分类">
          <el-option label="Zone one" value="shanghai" />
          <el-option label="Zone two" value="beijing" />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select placeholder="请选择三级分类">
          <el-option label="Zone one" value="shanghai" />
          <el-option label="Zone two" value="beijing" />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
import { defineComponent, onMounted, ref } from "vue";

export default defineComponent({
  name: "Category",
});
</script>

<script setup lang="ts">
import useCategoryStore from "@/stores/category";
import { ElMessage } from "element-plus";
import { storeToRefs } from "pinia";
const categoryStore = useCategoryStore();

//获取pinia中一级分类的数据
const { category1List } = storeToRefs(categoryStore);

//收集一级分类的选中的值
const category1Id = ref<null | number>(null);
//初始的时候首先请求一级分类列表
onMounted(() => {
  try {
    categoryStore.getCategory1List();
  } catch (e: any) {
    ElMessage.error(e.message);
  }
});
</script>

<style scoped></style>
